import wx
import ctypes
# set dpi
ctypes.windll.user32.SetProcessDPIAware(2)


class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title="Todo", size=wx.Size(600, 400))
        panel = wx.Panel(self)
        self._input = wx.TextCtrl(
            panel, pos=wx.Point(0, 0), size=wx.Size(500, 50))
        self._search_input = wx.TextCtrl(
            panel, pos=wx.Point(0, 50), size=wx.Size(500, 50))
        self._add_btn = wx.Button(
            panel, label="Add", pos=wx.Point(500, 0), size=wx.Size(80, 50))
        self._rm_btn = wx.Button(
            panel, label="Remove", pos=wx.Point(500, 50), size=wx.Size(80, 50))
        self._search_input.Bind(wx.EVT_TEXT, self.OnSearch)
        self._add_btn.Bind(wx.EVT_BUTTON, self.OnAdd)
        self._rm_btn.Bind(wx.EVT_BUTTON, self.OnRemove)
        self._list = wx.ListBox(panel, pos=wx.Point(
            0, 100), size=wx.Size(600, 300))
        self._all_tasks = []
        self.Show()

    def OnAdd(self, event):
        text = self._input.GetValue()
        if text:
            self._all_tasks.append(text)
            self._input.SetValue("")
            self.refresh_list()

    def OnRemove(self, event):
        selected = self._list.GetSelection()
        if selected != wx.NOT_FOUND:
            self._list.Delete(selected)

    def OnSearch(self, event):
        self.refresh_list()

    def refresh_list(self):
        keyword = self._search_input.GetValue().strip().lower()
        if keyword:
            filterd = [
                task for task in self._all_tasks if keyword in task.lower()]
        else:
            filterd = self._all_tasks.copy()
        self._list.SetItems(filterd)


app = wx.App()
frame = MyFrame()
app.MainLoop()
